/**
 * @author        Nicolas Bottarini <nicolasbottarini@gmail.com>, 404 <http://www.proyecto404.com>
 * @version       $Rev: 3 $
 * @lastrevision  $Date: 2011-09-12 16:45:37 +0000 (Mon, 12 Sep 2011) $	 
 */
package com.proyecto404.core.mvc {
	import com.proyecto404.core.BaseObject;
	import com.proyecto404.core.collections.Dictionary;
	import com.proyecto404.core.exception.InvalidOperationException;
	import com.proyecto404.core.log.fireflash.Console;
	
	public class FrontController extends BaseObject {
		private var _notifications:Dictionary;
		
		public function FrontController() {
			super();
			_notifications = new Dictionary();
		}
		
		public function registerNotification(notificationName:String, action:Action):void {
			_notifications.add(notificationName, action);
		}
		
		public function isRegistered(notificationName:String):Boolean {
			return _notifications.containsKey(notificationName);
		}
		
		public function dispatchNotification(notification:Notification):void {
			if (!_notifications.containsKey(notification.name)) {
				throw new InvalidOperationException("Notification with name " + notification.name + " doesn't have a registered action");
			}

			var action:Action = _notifications.get(notification.name);
			Console.debug("[FrontController] executing action '" + action.actionName +  "'");
			action.execute(notification);
		}
	}
}